library(ggplot2)         #for data visualisation 
library(marginaleffects) #for plotting marginal effects
library(mclogit)         #for conditional logit models 
library(patchwork)       #for combining plots
library(ragg)            #for saving data viz in png
library(showtext)        #for displaying fonts in data viz
library(stargazer)       #for model tables in latex
library(survival)        #alternative package for conditional logistic regressions
library(tidyverse)       #for data-wrangling

##data-wrangling----
BrSenSwitch <- read.csv("BrSenSwitch.csv", sep = ";") %>%
               mutate(fusao = ifelse(is.na(fusao), 0, fusao)) %>%
               mutate(fissao = ifelse(is.na(fissao), 0, fissao)) %>%
               mutate(partido_novo = ifelse(is.na(partido_novo), 0, partido_novo)) %>%
               mutate(home_inverted = 1-home) %>%
               filter(partido_novo != 1,
                      fissao != 1) %>%
               mutate(to_be_elected = case_when(legislatura == 48 ~ 1,
                                                legislatura == 49 ~ 2,
                                                legislatura == 50 ~ 1,
                                                legislatura == 51 ~ 2,
                                                legislatura == 52 ~ 1,
                                                legislatura == 53 ~ 2,
                                                legislatura == 54 ~ 1,
                                                legislatura == 55 ~ 2,
                                                legislatura == 56 ~ 1))

double_renovation <- BrSenSwitch %>% filter(to_be_elected == 2) 
single_renovation <- BrSenSwitch %>% filter(to_be_elected == 1)

##fonts----
font_add(family = "regular", "Barlow Semi Condensed-Regular.ttf")
font_add(family = "bold", "BarlowSemiCondensed-SemiBold.ttf")
showtext_auto() 

##models underlying marginal effects----
model_c <- mclogit(
  y|choice ~ alt_swps + dif1 + party_str*elec_comp + 
    home + coligacao_governador + suplente*home_inverted + legislaturas_participadas*home_inverted + pop_rural*home_inverted,
  data = BrSenSwitch)

model_e <- mclogit(
  y|choice ~ alt_swps + dif1 + party_str + party_str*elec_comp +
    home + coligacao_governador + suplente*home_inverted + legislaturas_participadas*home_inverted + pop_rural*home_inverted,
  data = single_renovation)

model_g <- mclogit(
  y|choice ~ alt_swps + dif1 + party_str*elec_comp + 
    home + coligacao_governador + suplente*home_inverted + legislaturas_participadas*home_inverted + pop_rural*home_inverted,
  data = double_renovation)

model_h <- mclogit(
  y|choice ~ alt_swps + dif1 + party_str + 
    alt_swps*dif1 + alt_swps*party_str + dif1*party_str +
    home + coligacao_governador + suplente*home_inverted + legislaturas_participadas*home_inverted + pop_rural*home_inverted,
  data = BrSenSwitch)

model_i <- mclogit(
  y|choice ~ alt_swps + dif1 + party_str + 
    alt_swps*dif1 + alt_swps*party_str + dif1*party_str + alt_swps*dif1*party_str +
    home + coligacao_governador + suplente*home_inverted + legislaturas_participadas*home_inverted + pop_rural*home_inverted,
  data = BrSenSwitch)

model_j <- mclogit(
  y|choice ~ alt_swps + dif1 + party_str + 
    alt_swps*dif1 + alt_swps*party_str + dif1*party_str +
    home + coligacao_governador + suplente*home_inverted + legislaturas_participadas*home_inverted + pop_rural*home_inverted,
  data = single_renovation)

model_k <- mclogit(
  y|choice ~ alt_swps + dif1 + party_str + 
    alt_swps*dif1 + alt_swps*party_str + dif1*party_str + alt_swps*dif1*party_str +
    home + coligacao_governador + suplente*home_inverted + legislaturas_participadas*home_inverted + pop_rural*home_inverted,
  data = single_renovation)

model_l <- mclogit(
  y|choice ~ alt_swps + dif1 + party_str + 
    alt_swps*dif1 + alt_swps*party_str + dif1*party_str +
    home + coligacao_governador + suplente*home_inverted + legislaturas_participadas*home_inverted + pop_rural*home_inverted,
  data = double_renovation)

model_m <- mclogit(
  y|choice ~ alt_swps + dif1 + party_str + 
    alt_swps*dif1 + alt_swps*party_str + dif1*party_str + alt_swps*dif1*party_str +
    home + coligacao_governador + suplente*home_inverted + legislaturas_participadas*home_inverted + pop_rural*home_inverted,
  data = double_renovation)




##Visualisation-I----
a0 <- plot_cme(model_c, variables = "party_str", condition = "elec_comp", type = "link", draw = F) 
a0.1 <- plot_cme(model_c, variables = "party_str", condition = "elec_comp", type = "link") +
  ggplot2::geom_line(data = a0, ggplot2::aes(x = elec_comp, 
                                             y = estimate), size = 0.8) +
  geom_rug(aes(x = elec_comp), data = BrSenSwitch)+
  ggplot2::geom_ribbon(data = a0, alpha = 0.3, ggplot2::aes(x = elec_comp, 
                                                            y = estimate, 
                                                            ymin = conf.low, 
                                                            ymax = conf.high)) +
  labs(title = "Full Dataset") +
  xlab("Electoral Competition") + ylab("M. E. of Party Strength on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"))  

e0 <- plot_cme(model_e, variables = "party_str", condition = "elec_comp", type = "link", draw = F) 
e1 <- plot_cme(model_e, variables = "party_str", condition = "elec_comp", type = "link") +
  ggplot2::geom_line(data = e0, ggplot2::aes(x = elec_comp, 
                                             y = estimate), linewidth = 0.8) +
  geom_rug(aes(x = elec_comp), data = BrSenSwitch %>% filter(elec_comp >= 0.6698468))+
  ggplot2::geom_ribbon(data = e0, alpha = 0.3, ggplot2::aes(x = elec_comp, 
                                                            y = estimate, 
                                                            ymin = conf.low, 
                                                            ymax = conf.high)) +
  labs(title = "M = 1") +
  xlab("Electoral Competition") + ylab("M. E. of Party Strength on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"))  




t0 <- plot_cme(model_g, variables = "party_str", condition = "elec_comp", type = "link", draw = F) 
t1 <- plot_cme(model_g, variables = "party_str", condition = "elec_comp", type = "link") +
  ggplot2::geom_line(data = t0, ggplot2::aes(x = elec_comp, 
                                             y = estimate), linewidth = 0.8) +
  geom_rug(aes(x = elec_comp), data = BrSenSwitch)+
  ggplot2::geom_ribbon(data = t0, alpha = 0.3, ggplot2::aes(x = elec_comp, 
                                                            y = estimate, 
                                                            ymin = conf.low, 
                                                            ymax = conf.high)) +
  labs(title = "M = 2") +
  xlab("Electoral Competition") + ylab("M. E. of Party Strength on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"))  

a0.1 / (e1 | t1)

##Visualisation-II----
b0 <- plot_cme(model_c, variables = "elec_comp", condition = "party_str", type = "link", draw = F) 
b0.1 <- plot_cme(model_c, variables = "elec_comp", condition = "party_str", type = "link") +
  ggplot2::geom_line(data = b0, ggplot2::aes(x = party_str, 
                                             y = estimate), size = 0.8) +
  geom_rug(aes(x = party_str), data = BrSenSwitch %>% filter(party_str <= 0.51471278))+
  ggplot2::geom_ribbon(data = b0, alpha = 0.3, ggplot2::aes(x = party_str, 
                                                            y = estimate, 
                                                            ymin = conf.low, 
                                                            ymax = conf.high)) +
  labs(title = "Full Dataset") +
  xlab("Party Strength") + ylab("M. E. of Elec. Competition on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"))  

f0 <- plot_cme(model_e, variables = "elec_comp", condition = "party_str", type = "link", draw = F) 
f1 <- plot_cme(model_e, variables = "elec_comp", condition = "party_str", type = "link") +
  ggplot2::geom_line(data = f0, ggplot2::aes(x = party_str, 
                                             y = estimate), linewidth = 0.8) +
  geom_rug(aes(x = party_str), data = BrSenSwitch %>% filter(party_str <= 0.51471278))+
  ggplot2::geom_ribbon(data = f0, alpha = 0.3, ggplot2::aes(x = party_str, 
                                                            y = estimate, 
                                                            ymin = conf.low, 
                                                            ymax = conf.high)) +
  labs(title = "M = 1") +
  xlab("Party Strength") + ylab("M. E. of Elec. Competition on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"))  




v0 <- plot_cme(model_g, variables = "elec_comp", condition = "party_str", type = "link", draw = F) 
v1 <- plot_cme(model_g, variables = "elec_comp", condition = "party_str", type = "link") +
  ggplot2::geom_line(data = v0, ggplot2::aes(x = party_str, 
                                             y = estimate), linewidth = 0.8) +
  geom_rug(aes(x = party_str), data = BrSenSwitch %>% filter(party_str <= 0.470512411))+
  ggplot2::geom_ribbon(data = v0, alpha = 0.3, ggplot2::aes(x = party_str, 
                                                            y = estimate, 
                                                            ymin = conf.low, 
                                                            ymax = conf.high)) +
  labs(title = "M = 2") +
  xlab("Party Strength") + ylab("M. E. of Elec. Competition on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"))  

b0.1 / (f1 | v1)
##Visualisation-III----
drowny <- plot_cme(model_h, variables = "party_str", condition = "dif1", type = "link", draw = F)
drown2 <- plot_cme(model_h, variables = "party_str", condition = "dif1", type = "link") +
  ggplot2::geom_line(data = drowny, ggplot2::aes(x = dif1, 
                                                 y = estimate), size = 0.8) +
  geom_rug(aes(x = dif1), data = BrSenSwitch) +
  ggplot2::geom_ribbon(data = drowny, alpha = 0.3, ggplot2::aes(x = dif1, 
                                                                y = estimate, 
                                                                ymin = conf.low, 
                                                                ymax = conf.high)) +
  labs(title = "Full Dataset") +
  xlab("Ideological Distance") + ylab("M. E. of Party Strength on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"))  

wash <- plot_cme(model_j, variables = "party_str", condition = "dif1", type = "link", draw = F)
drown4 <- plot_cme(model_j, variables = "party_str", condition = "dif1", type = "link") +
  ggplot2::geom_line(data = wash, ggplot2::aes(x = dif1, 
                                               y = estimate), size = 0.8) +
  geom_rug(aes(x = dif1), data = BrSenSwitch) +
  ggplot2::geom_ribbon(data = wash, alpha = 0.3, ggplot2::aes(x = dif1, 
                                                              y = estimate, 
                                                              ymin = conf.low, 
                                                              ymax = conf.high)) +
  labs(title = "M = 1") +
  xlab("Ideological Distance") + ylab("M. E. of Party Strength on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"))  

t4 <- plot_cme(model_l, variables = "party_str", condition = "dif1", type = "link", draw = F)
t4.1 <- plot_cme(model_l, variables = "party_str", condition = "dif1", type = "link") +
  ggplot2::geom_line(data = t4, ggplot2::aes(x = dif1, 
                                             y = estimate), size = 0.8) +
  geom_rug(aes(x = dif1), data = BrSenSwitch) +
  ggplot2::geom_ribbon(data = t4, alpha = 0.3, ggplot2::aes(x = dif1, 
                                                            y = estimate, 
                                                            ymin = conf.low, 
                                                            ymax = conf.high)) +
  labs(title = "M = 2") +
  xlab("Ideological Distance") + ylab("M. E. of Party Strength on P.S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"))  

drown2 / (drown4 | t4.1)

##Visualisation-IV.----
tali <- plot_cme(model_h, variables = "alt_swps", condition = "party_str", type = "link", draw = F)
tal2 <- plot_cme(model_h, variables = "alt_swps", condition = "party_str", type = "link") +   
  ggplot2::geom_line(data = tali, ggplot2::aes(x = party_str, 
                                               y = estimate), size = 0.8) +
  geom_rug(aes(x = party_str), data = BrSenSwitch %>% filter(party_str <= 0.51471278))+
  ggplot2::geom_ribbon(data = tali, alpha = 0.3, ggplot2::aes(x = party_str, 
                                                              y = estimate, 
                                                              ymin = conf.low, 
                                                              ymax = conf.high)) +
  labs(title = "Full Dataset") +
  xlab("Party Strength") + ylab("M. E. of Weigh. Coal. Part. on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 30, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=30, family="regular", color="black"),
    axis.text.y = element_text(size=20, family="regular", color="black"),
    axis.text.x = element_text(size=20, family="regular", color="black"))  


talo1 <- plot_cme(model_j, variables = "alt_swps", condition = "party_str", type = "link", draw = F)
tal4 <- plot_cme(model_j, variables = "alt_swps", condition = "party_str", type = "link") +   
  ggplot2::geom_line(data = talo1, ggplot2::aes(x = party_str, 
                                                y = estimate), size = 0.8) +
  geom_rug(aes(x = party_str), data = BrSenSwitch %>% filter(party_str <= 0.51471278))+
  ggplot2::geom_ribbon(data = talo1, alpha = 0.3, ggplot2::aes(x = party_str, 
                                                               y = estimate, 
                                                               ymin = conf.low, 
                                                               ymax = conf.high)) +
  labs(title = "M = 1") +
  xlab("Party Strength") + ylab("M. E. of Weigh. Coal. Part. on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 30, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=30, family="regular", color="black"),
    axis.text.y = element_text(size=20, family="regular", color="black"),
    axis.text.x = element_text(size=20, family="regular", color="black"))  


surrot <- plot_cme(model_l, variables = "alt_swps", condition = "party_str", type = "link", draw = F)
tal6 <- plot_cme(model_l, variables = "alt_swps", condition = "party_str", type = "link") +   
  ggplot2::geom_line(data = surrot, ggplot2::aes(x = party_str, 
                                                 y = estimate), size = 0.8) +
  geom_rug(aes(x = party_str), data = BrSenSwitch %>% filter(party_str <= 0.51471278))+
  ggplot2::geom_ribbon(data = surrot, alpha = 0.3, ggplot2::aes(x = party_str, 
                                                                y = estimate, 
                                                                ymin = conf.low, 
                                                                ymax = conf.high)) +
  labs(title = "M = 2") +
  xlab("Party Strength") + ylab("M. E. of Weigh. Coal. Part. on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 30, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=30, family="regular", color="black"),
    axis.text.y = element_text(size=20, family="regular", color="black"),
    axis.text.x = element_text(size=20, family="regular", color="black"))  

tal2 / (tal4 | tal6) 

##Visualisation-V----
tal <- plot_cme(model_h, variables = "alt_swps", condition = "dif1", type = "link", draw = F)
tal1 <- plot_cme(model_h, variables = "alt_swps", condition = "dif1", type = "link") +
  ggplot2::geom_line(data = tal, ggplot2::aes(x = dif1, 
                                              y = estimate), size = 0.8) +
  geom_rug(aes(x = dif1), data = BrSenSwitch) +
  ggplot2::geom_ribbon(data = tal, alpha = 0.3, ggplot2::aes(x = dif1, 
                                                             y = estimate, 
                                                             ymin = conf.low, 
                                                             ymax = conf.high)) +
  labs(title = "Full Dataset") +
  xlab("Ideological Distance") + ylab("M. E. of Weigh. Coal. Part. on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 30, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=30, family="regular", color="black"),
    axis.text.y = element_text(size=20, family="regular", color="black"),
    axis.text.x = element_text(size=20, family="regular", color="black"))  

talo <- plot_cme(model_j, variables = "alt_swps", condition = "dif1", type = "link", draw = F)
tal3 <- plot_cme(model_j, variables = "alt_swps", condition = "dif1", type = "link") +
  ggplot2::geom_line(data = talo, ggplot2::aes(x = dif1, 
                                               y = estimate), size = 0.8) +
  geom_rug(aes(x = dif1), data = BrSenSwitch) +
  ggplot2::geom_ribbon(data = talo, alpha = 0.3, ggplot2::aes(x = dif1, 
                                                              y = estimate, 
                                                              ymin = conf.low, 
                                                              ymax = conf.high)) +
  labs(title = "M = 1") +
  xlab("Ideological Distance") + ylab("M. E. of Weigh. Coal. Part. on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 30, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=30, family="regular", color="black"),
    axis.text.y = element_text(size=20, family="regular", color="black"),
    axis.text.x = element_text(size=20, family="regular", color="black"))  

surro <- plot_cme(model_l, variables = "alt_swps", condition = "dif1", type = "link", draw = F)
tal5 <- plot_cme(model_l, variables = "alt_swps", condition = "dif1", type = "link") +
  ggplot2::geom_line(data = surro, ggplot2::aes(x = dif1, 
                                                y = estimate), size = 0.8) +
  geom_rug(aes(x = dif1), data = BrSenSwitch) +
  ggplot2::geom_ribbon(data = surro, alpha = 0.3, ggplot2::aes(x = dif1, 
                                                               y = estimate, 
                                                               ymin = conf.low, 
                                                               ymax = conf.high)) +
  labs(title = "M = 2") +
  xlab("Ideological Distance") + ylab("M. E. of Weigh. Coal. Part. on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 30, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=30, family="regular", color="black"),
    axis.text.y = element_text(size=20, family="regular", color="black"),
    axis.text.x = element_text(size=20, family="regular", color="black"))  

tal1 / (tal3 | tal5) 


##Visualisation-VI----
hoo <- plot_cme(model_i, variables = "dif1", condition = c("party_str", "alt_swps"), type = "link", draw = F)
hoo1 <- plot_cme(model_i, variables = "dif1", condition = c("party_str", "alt_swps"), type = "link") +
  ggplot2::geom_line(data = hoo %>% filter(alt_swps == 0), ggplot2::aes(x = party_str, 
                                                                        y = estimate,
                                                                        color = factor(alt_swps)), size = 0.8) +
  scale_fill_discrete(labels = c("0", "0.782", "7.046"), name = "Weigh. \nPart. in Coal.") +
  scale_colour_discrete(labels = c("0", "0.782", "7.046"), name = "Weigh. \nPart. in Coal.") +
  geom_rug(aes(x = party_str), data = BrSenSwitch %>% filter(party_str <= 0.5147128)) +
  #ggplot2::geom_ribbon(data = b1 %>% filter(party_str == 0.0504941655872341), alpha = 0.8, ggplot2::aes(x = alt_swps, 
  #                                                          y = estimate, 
  #                                                          ymin = conf.low, 
  #                                                          ymax = conf.high,
  #                                                          fill = party_str))
  labs(title = "Full Dataset") +
  xlab("Party Strength") + ylab("M. E. of Ideological Distance on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"),
    ##Legend
    legend.position = "top",
    legend.background = element_rect(fill = "white"),
    legend.key = element_rect(fill = "white"),
    legend.title = element_text(margin = margin(b = 10), family="regular",size=15),
    text = element_text(size = 15))  

hooy <- plot_cme(model_k, variables = "dif1", condition = c("party_str", "alt_swps"), type = "link", draw = F)
hoo2 <- plot_cme(model_k, variables = "dif1", condition = c("party_str", "alt_swps"), type = "link") +
  ggplot2::geom_line(data = hooy %>% filter(alt_swps == 0), ggplot2::aes(x = party_str, 
                                                                         y = estimate,
                                                                         color = factor(alt_swps)), size = 0.8) +
  scale_fill_discrete(labels = c("0", "0.13", "0.782", "7.046"), name = "Weigh. \nPart. in Coal.") +
  scale_colour_discrete(labels = c("0", "0.13", "0.782", "7.046"), name = "Weigh. \nPart. in Coal.") +
  geom_rug(aes(x = party_str), data = BrSenSwitch %>% filter(party_str <= 0.5147128)) +
  #ggplot2::geom_ribbon(data = b1 %>% filter(party_str == 0.0504941655872341), alpha = 0.8, ggplot2::aes(x = alt_swps, 
  #                                                          y = estimate, 
  #                                                          ymin = conf.low, 
  #                                                          ymax = conf.high,
  #                                                          fill = party_str))
  labs(title = "M = 1") +
  xlab("Party Strength") + ylab("M. E. of Ideological Distance on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"),
    ##Legend
    legend.position = "top",
    legend.background = element_rect(fill = "white"),
    legend.key = element_rect(fill = "white"),
    legend.title = element_text(margin = margin(b = 10), family="regular",size=15),
    text = element_text(size = 15))  

hoox <- plot_cme(model_m, variables = "dif1", condition = c("party_str", "alt_swps"), type = "link", draw = F)
hoo3 <- plot_cme(model_m, variables = "dif1", condition = c("party_str", "alt_swps"), type = "link") +
  ggplot2::geom_line(data = hoox %>% filter(alt_swps == 0), ggplot2::aes(x = party_str, 
                                                                         y = estimate,
                                                                         color = factor(alt_swps)), size = 0.8) +
  scale_fill_discrete(labels = c("0", "0.838", "5.036"), name = "Weigh. \nPart. in Coal.") +
  scale_colour_discrete(labels = c("0", "0.838", "5.036"), name = "Weigh. \nPart. in Coal.") +
  geom_rug(aes(x = party_str), data = BrSenSwitch %>% filter(party_str <= 0.470512411)) +
  #ggplot2::geom_ribbon(data = b1 %>% filter(party_str == 0.0504941655872341), alpha = 0.8, ggplot2::aes(x = alt_swps, 
  #                                                          y = estimate, 
  #                                                          ymin = conf.low, 
  #                                                          ymax = conf.high,
  #                                                          fill = party_str)) 
  labs(title = "M = 2") +
  xlab("Party Strength") + ylab("M. E. of Ideological Distance on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"),
    ##Legend
    legend.position = "top",
    legend.background = element_rect(fill = "white"),
    legend.key = element_rect(fill = "white"),
    legend.title = element_text(margin = margin(b = 10), family="regular",size=15),
    text = element_text(size = 15))  

hoo1 / (hoo2 | hoo3)


##Visualisation-VII----
pro <- plot_cme(model_i, variables = "alt_swps", condition = c("dif1", "party_str"), type = "link", draw = F)
pro1 <- plot_cme(model_i, variables = "alt_swps", condition = c("dif1", "party_str"), type = "link") +
  ggplot2::geom_line(data = pro %>% filter(party_str == 0), ggplot2::aes(x = dif1, 
                                                                         y = estimate,
                                                                         color = factor(party_str)), size = 0.8) +
  scale_fill_discrete(labels = c("0%", "1.49%", "4.77%", "10.54%", "51.47%"), name = "Party \nStrength") +
  scale_colour_discrete(labels = c("0%", "1.49%", "4.77%", "10.54%", "51.47%"), name = "Party \nStrength") +
  geom_rug(aes(x = dif1), data = BrSenSwitch) +
  #ggplot2::geom_ribbon(data = b1 %>% filter(party_str == 0.0504941655872341), alpha = 0.8, ggplot2::aes(x = alt_swps, 
  #                                                          y = estimate, 
  #                                                          ymin = conf.low, 
  #                                                          ymax = conf.high,
  #                                                          fill = party_str))
  labs(title = "Full Dataset") +
  xlab("Ideological Distance") + ylab("M. E. of Weigh. Coal. Part. on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"),
    ##Legend
    legend.position = "top",
    legend.background = element_rect(fill = "white"),
    legend.key = element_rect(fill = "white"),
    legend.title = element_text(margin = margin(b = 10), family="regular",size=15),
    text = element_text(size = 15))  

prow <- plot_cme(model_k, variables = "alt_swps", condition = c("dif1", "party_str"), type = "link", draw = F)
pro2 <- plot_cme(model_k, variables = "alt_swps", condition = c("dif1", "party_str"), type = "link") +
  ggplot2::geom_line(data = prow %>% filter(party_str == 0), ggplot2::aes(x = dif1, 
                                                                          y = estimate,
                                                                          color = factor(party_str)), size = 0.8) +
  scale_fill_discrete(labels = c("0%", "1.62%", "4.54%", "9.89%", "51.47%"), name = "Party \nStrength") +
  scale_colour_discrete(labels = c("0%", "1.62%", "4.54%", "9.89%", "51.47%"), name = "Party \nStrength") +
  geom_rug(aes(x = dif1), data = BrSenSwitch) +
  #ggplot2::geom_ribbon(data = b1 %>% filter(party_str == 0.0504941655872341), alpha = 0.8, ggplot2::aes(x = alt_swps, 
  #                                                          y = estimate, 
  #                                                          ymin = conf.low, 
  #                                                          ymax = conf.high,
  #                                                          fill = party_str))
  labs(title = "M = 1") +
  xlab("Ideological Distance") + ylab("M. E. of Weigh. Coal. Part. on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"),
    ##Legend
    legend.position = "top",
    legend.background = element_rect(fill = "white"),
    legend.key = element_rect(fill = "white"),
    legend.title = element_text(margin = margin(b = 10), family="regular",size=15),
    text = element_text(size = 15))  

prowe <- plot_cme(model_m, variables = "alt_swps", condition = c("dif1", "party_str"), type = "link", draw = F)
pro3 <- plot_cme(model_m, variables = "alt_swps", condition = c("dif1", "party_str"), type = "link") +
  ggplot2::geom_line(data = prowe %>% filter(party_str == 0), ggplot2::aes(x = dif1, 
                                                                           y = estimate,
                                                                           color = factor(party_str)), size = 0.8) +
  scale_fill_discrete(labels = c("0%", "1.37%", "5.05%", "11.48%", "47.05%"), name = "Party \nStrength") +
  scale_colour_discrete(labels = c("0%", "1.37%", "5.05%", "11.48%", "47.05%"), name = "Party \nStrength") +
  geom_rug(aes(x = dif1), data = BrSenSwitch) +
  #ggplot2::geom_ribbon(data = b1 %>% filter(party_str == 0.0504941655872341), alpha = 0.8, ggplot2::aes(x = alt_swps, 
  #                                                          y = estimate, 
  #                                                          ymin = conf.low, 
  #                                                          ymax = conf.high,
  #                                                          fill = party_str)) 
  labs(title = "M = 2") +
  xlab("Ideological Distance") + ylab("M. E. of Weigh. Coal. Part. on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"),
    ##Legend
    legend.position = "top",
    legend.background = element_rect(fill = "white"),
    legend.key = element_rect(fill = "white"),
    legend.title = element_text(margin = margin(b = 10), family="regular",size=15),
    text = element_text(size = 15))  

pro1 / (pro2 | pro3)
##Visualisation-VIII----
hij <- plot_cme(model_i, variables = "alt_swps", condition = c("party_str", "dif1"), type = "link", draw = F)
hij1 <- plot_cme(model_i, variables = "alt_swps", condition = c("party_str", "dif1"), type = "link") +
  ggplot2::geom_line(data = hij %>% filter(alt_swps == 0), ggplot2::aes(x = party_str, 
                                                                        y = estimate,
                                                                        color = factor(party_str)), size = 0.8) +
  scale_fill_discrete(labels = c("0", "0.175", "0.443", "0.946", "1.972"), name = "Ideological \nDistance") +
  scale_colour_discrete(labels = c("0", "0.175", "0.443", "0.946", "1.972"), name = "Ideological \nDistance") +
  geom_rug(aes(x = party_str), data = BrSenSwitch %>% filter(party_str <= 0.5147128)) +
  #ggplot2::geom_ribbon(data = b1 %>% filter(party_str == 0.0504941655872341), alpha = 0.8, ggplot2::aes(x = alt_swps, 
  #                                                          y = estimate, 
  #                                                          ymin = conf.low, 
  #                                                          ymax = conf.high,
  #                                                          fill = party_str))
  labs(title = "Full Dataset") +
  xlab("Party Strength") + ylab("M. E. of Weigh. Coal. Part. on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"),
    ##Legend
    legend.position = "top",
    legend.background = element_rect(fill = "white"),
    legend.key = element_rect(fill = "white"),
    legend.title = element_text(margin = margin(r = 10), family="regular",size=15),
    text = element_text(size = 15))  

hiji <- plot_cme(model_k, variables = "alt_swps", condition = c("party_str", "dif1"), type = "link", draw = F)
hij2 <- plot_cme(model_k, variables = "alt_swps", condition = c("party_str", "dif1"), type = "link") +
  ggplot2::geom_line(data = hiji %>% filter(alt_swps == 0), ggplot2::aes(x = party_str, 
                                                                         y = estimate,
                                                                         color = factor(alt_swps)), size = 0.8) +
  scale_fill_discrete(labels = c("0", "0.181", "0.484", "1.054", "1.972"), name = "Ideological \nDistance") +
  scale_colour_discrete(labels = c("0", "0.181", "0.484", "1.054", "1.972"), name = "Ideological \nDistance") +
  geom_rug(aes(x = party_str), data = BrSenSwitch %>% filter(party_str <= 0.5147128)) +
  #ggplot2::geom_ribbon(data = b1 %>% filter(party_str == 0.0504941655872341), alpha = 0.8, ggplot2::aes(x = alt_swps, 
  #                                                          y = estimate, 
  #                                                          ymin = conf.low, 
  #                                                          ymax = conf.high,
  #                                                          fill = party_str))
  labs(title = "M = 1") +
  xlab("Party Strength") + ylab("M. E. of Weigh. Coal. Part. on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"),
    ##Legend
    legend.position = "top",
    legend.background = element_rect(fill = "white"),
    legend.key = element_rect(fill = "white"),
    legend.title = element_text(margin = margin(r = 10), family="regular",size=15),
    text = element_text(size = 15))  

hijo <- plot_cme(model_m, variables = "alt_swps", condition = c("party_str", "dif1"), type = "link", draw = F)
hij3 <- plot_cme(model_m, variables = "alt_swps", condition = c("party_str", "dif1"), type = "link") +
  ggplot2::geom_line(data = hijo %>% filter(alt_swps == 0), ggplot2::aes(x = party_str, 
                                                                         y = estimate,
                                                                         color = factor(alt_swps)), size = 0.8) +
  scale_fill_discrete(labels = c("0", "0.170", "0.409", "0.803", "1.963"), name = "Ideological \nDistance") +
  scale_colour_discrete(labels = c("0", "0.170", "0.409", "0.803", "1.963"), name = "Ideological \nDistance") +
  geom_rug(aes(x = party_str), data = BrSenSwitch %>% filter(party_str <= 0.470512411)) +
  #ggplot2::geom_ribbon(data = b1 %>% filter(party_str == 0.0504941655872341), alpha = 0.8, ggplot2::aes(x = alt_swps, 
  #                                                          y = estimate, 
  #                                                          ymin = conf.low, 
  #                                                          ymax = conf.high,
  #                                                          fill = party_str)) 
  labs(title = "M = 2") +
  xlab("Party Strength") + ylab("M. E. of Weigh. Coal. Part. on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"),
    ##Legend
    legend.position = "top",
    legend.background = element_rect(fill = "white"),
    legend.key = element_rect(fill = "white"),
    legend.title = element_text(margin = margin(r = 10), family="regular",size=15),
    text = element_text(size = 15))  

hij1 / (hij2 | hij3)
##Visualisation-IX----
ste <- plot_cme(model_i, variables = "party_str", condition = c("alt_swps", "dif1"), type = "link", draw = F)
ste1 <- plot_cme(model_i, variables = "party_str", condition = c("alt_swps", "dif1"), type = "link") +
  ggplot2::geom_line(data = ste %>% filter(dif1 == 0), ggplot2::aes(x = alt_swps, 
                                                                    y = estimate,
                                                                    color = factor(dif1)), size = 0.8) +
  scale_fill_discrete(labels = c("0", "0.175", "0.443", "0.946", "1.972"), name = "Ideological \nDistance") +
  scale_colour_discrete(labels = c("0", "0.175", "0.443", "0.946", "1.972"), name = "Ideological \nDistance") +
  geom_rug(aes(x = alt_swps), data = BrSenSwitch) +
  #ggplot2::geom_ribbon(data = b1 %>% filter(party_str == 0.0504941655872341), alpha = 0.8, ggplot2::aes(x = alt_swps, 
  #                                                          y = estimate, 
  #                                                          ymin = conf.low, 
  #                                                          ymax = conf.high,
  #                                                          fill = party_str))
  labs(title = "Full Dataset") +
  xlab("Weighted Participation in Coalition") + ylab("M. E. of Party Strength on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"),
    ##Legend
    legend.position = "top",
    legend.background = element_rect(fill = "white"),
    legend.key = element_rect(fill = "white"),
    legend.title = element_text(margin = margin(r = 10), family="regular",size=15),
    text = element_text(size = 15))  

stee <- plot_cme(model_k, variables = "party_str", condition = c("alt_swps", "dif1"), type = "link", draw = F)
ste2 <- plot_cme(model_k, variables = "party_str", condition = c("alt_swps", "dif1"), type = "link") +
  ggplot2::geom_line(data = stee %>% filter(dif1 == 0), ggplot2::aes(x = alt_swps, 
                                                                     y = estimate,
                                                                     color = factor(dif1)), size = 0.8) +
  scale_fill_discrete(labels = c("0", "0.181", "0.484", "1.054", "1.972"), name = "Ideological \nDistance") +
  scale_colour_discrete(labels = c("0", "0.181", "0.484", "1.054", "1.972"), name = "Ideological \nDistance") +
  geom_rug(aes(x = alt_swps), data = BrSenSwitch) +
  #ggplot2::geom_ribbon(data = b1 %>% filter(party_str == 0.0504941655872341), alpha = 0.8, ggplot2::aes(x = alt_swps, 
  #                                                          y = estimate, 
  #                                                          ymin = conf.low, 
  #                                                          ymax = conf.high,
  #                                                          fill = party_str))
  labs(title = "M = 1") +
  xlab("Weighted Participation in Coalition") + ylab("M. E. of Party Strength on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"),
    ##Legend
    legend.position = "top",
    legend.background = element_rect(fill = "white"),
    legend.key = element_rect(fill = "white"),
    legend.title = element_text(margin = margin(r = 10), family="regular",size=15),
    text = element_text(size = 15))  

stw <- plot_cme(model_m, variables = "party_str", condition = c("alt_swps", "dif1"), type = "link", draw = F)
ste3 <- plot_cme(model_m, variables = "party_str", condition = c("alt_swps", "dif1"), type = "link") +
  ggplot2::geom_line(data = stw %>% filter(dif1 == 0), ggplot2::aes(x = alt_swps, 
                                                                    y = estimate,
                                                                    color = factor(dif1)), size = 0.8) +
  scale_fill_discrete(labels = c("0", "0.170", "0.409", "0.803", "1.963"), name = "Ideological \nDistance") +
  scale_colour_discrete(labels = c("0", "0.170", "0.409", "0.803", "1.963"), name = "Ideological \nDistance") +
  geom_rug(aes(x = alt_swps), data = BrSenSwitch %>% filter(alt_swps <= 5.036000)) +
  #ggplot2::geom_ribbon(data = b1 %>% filter(party_str == 0.0504941655872341), alpha = 0.8, ggplot2::aes(x = alt_swps, 
  #                                                          y = estimate, 
  #                                                          ymin = conf.low, 
  #                                                          ymax = conf.high,
  #                                                          fill = party_str)) 
  labs(title = "M = 2") +
  xlab("Weighted Participation in Coalition") + ylab("M. E. of Party Strength on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"),
    ##Legend
    legend.position = "top",
    legend.background = element_rect(fill = "white"),
    legend.key = element_rect(fill = "white"),
    legend.title = element_text(margin = margin(r = 10), family="regular",size=15),
    text = element_text(size = 15))  

ste1 / (ste2 | ste3)
##Visualisation-X----
krz <- plot_cme(model_i, variables = "party_str", condition = c("dif1", "alt_swps"), type = "link", draw = F)
krz1 <- plot_cme(model_i, variables = "party_str", condition = c("dif1", "alt_swps"), type = "link") +
  ggplot2::geom_line(data = krz %>% filter(alt_swps == 0), ggplot2::aes(x = dif1, 
                                                                        y = estimate,
                                                                        color = factor(alt_swps)), size = 0.8) +
  scale_fill_discrete(labels = c("0", "0.782","7.046"), name = "Weigh. \nPart. in Coal.") +
  scale_colour_discrete(labels = c("0", "0.782", "7.046"), name = "Weigh. \nPart. in Coal.") +
  geom_rug(aes(x = dif1), data = BrSenSwitch) +
  #ggplot2::geom_ribbon(data = b1 %>% filter(party_str == 0.0504941655872341), alpha = 0.8, ggplot2::aes(x = alt_swps, 
  #                                                          y = estimate, 
  #                                                          ymin = conf.low, 
  #                                                          ymax = conf.high,
  #                                                          fill = party_str))
  labs(title = "Full Dataset") +
  xlab("Ideological Distance") + ylab("M. E. of Party Strength on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"),
    ##Legend
    legend.position = "top",
    legend.background = element_rect(fill = "white"),
    legend.key = element_rect(fill = "white"),
    legend.title = element_text(margin = margin(r = 10), family="regular",size=15),
    text = element_text(size = 15))  

krza <- plot_cme(model_k, variables = "party_str", condition = c("dif1", "alt_swps"), type = "link", draw = F)
krz2 <- plot_cme(model_k, variables = "party_str", condition = c("dif1", "alt_swps"), type = "link") +
  ggplot2::geom_line(data = krza %>% filter(alt_swps == 0), ggplot2::aes(x = dif1, 
                                                                         y = estimate,
                                                                         color = factor(alt_swps)), size = 0.8) +
  scale_fill_discrete(labels = c("0", "0.130", "0.782", "7.046"), name = "Weigh. \nPart. in Coal.") +
  scale_colour_discrete(labels = c("0", "0.130", "0.782", "7.046"), name = "Weigh. \nPart. in Coal.") +
  geom_rug(aes(x = dif1), data = BrSenSwitch) +
  #ggplot2::geom_ribbon(data = b1 %>% filter(party_str == 0.0504941655872341), alpha = 0.8, ggplot2::aes(x = alt_swps, 
  #                                                          y = estimate, 
  #                                                          ymin = conf.low, 
  #                                                          ymax = conf.high,
  #                                                          fill = party_str))
  labs(title = "M = 1") +
  xlab("Ideological Distance") + ylab("M. E. of Party Strength on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"),
    ##Legend
    legend.position = "top",
    legend.background = element_rect(fill = "white"),
    legend.key = element_rect(fill = "white"),
    legend.title = element_text(margin = margin(r = 10), family="regular",size=15),
    text = element_text(size = 15))  

krzq <- plot_cme(model_m, variables = "party_str", condition = c("dif1", "alt_swps"), type = "link", draw = F)
krz3 <- plot_cme(model_m, variables = "party_str", condition = c("dif1", "alt_swps"), type = "link") +
  ggplot2::geom_line(data = krzq %>% filter(alt_swps == 0), ggplot2::aes(x = dif1, 
                                                                         y = estimate,
                                                                         color = factor(alt_swps)), size = 0.8) +
  scale_fill_discrete(labels = c("0", "0.838", "5.036"), name = "Weigh. \nPart. in Coal.") +
  scale_colour_discrete(labels = c("0", "0.838", "5.036"), name = "Weigh. \nPart. in Coal.") +
  geom_rug(aes(x = dif1), data = BrSenSwitch %>% filter(alt_swps <= 5.036000)) +
  #ggplot2::geom_ribbon(data = b1 %>% filter(party_str == 0.0504941655872341), alpha = 0.8, ggplot2::aes(x = alt_swps, 
  #                                                          y = estimate, 
  #                                                          ymin = conf.low, 
  #                                                          ymax = conf.high,
  #                                                          fill = party_str)) 
  labs(title = "M = 2") +
  xlab("Ideological Distance") + ylab("M. E. of Party Strength on P. S.") +
  theme(
    plot.title = element_text(family = "bold", hjust = 0.5, vjust = 0.5, size = 20, color = "black"),
    ##Background
    panel.border=element_blank(),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    plot.background = element_rect(fill = "#ffffff", linetype = 'blank'),
    panel.background = element_rect(fill = "#ffffff"),
    ##Axes
    axis.title = element_text(size=20, family="regular", color="black"),
    axis.text.y = element_text(size=15, family="regular", color="black"),
    axis.text.x = element_text(size=15, family="regular", color="black"),
    ##Legend
    legend.position = "top",
    legend.background = element_rect(fill = "white"),
    legend.key = element_rect(fill = "white"),
    legend.title = element_text(margin = margin(r = 10), family="regular",size=15),
    text = element_text(size = 15))  

krz1 / (krz2 | krz3)